package com.ruoyi.smart.service;

import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class DeviceStatisticsService {

    private final DeviceStatusService deviceStatusService;

    public DeviceStatisticsService(DeviceStatusService deviceStatusService) {
        this.deviceStatusService = deviceStatusService;
    }

    /**
     * 获取设备统计信息
     * @return 设备统计信息
     */
    public Map<String, Object> getDeviceStatistics() {
        Map<String, Boolean> allStatus = deviceStatusService.getAllDeviceStatus();
        long total = allStatus.size();
        long online = allStatus.values().stream().filter(Boolean::booleanValue).count();
        long offline = total - online;

        return Map.of(
                "total", total,
                "online", online,
                "offline", offline,
                "onlineRate", total > 0 ? (double) online / total : 0
        );
    }
}
